/**
 * const 对象和非 const对象都可以调用 const 函数，但是const对象不能调用一个非const函数
 */
#include<iostream>

using namespace std;

class Sample {
    int val;

public:
    Sample(int x = 0) {
        val = x;
    }

    int getValue() const {
        return val;
    }

    int getValue1() {
        return val;
    }
};

int main() {
    const Sample s{20};
    Sample s1{2};

    cout << "The const function called by const object s : " << s.getValue();
    cout << "\nThe const function called by non-const object s1 : " << s1.getValue();
    cout << "\nThe non-const function called by non-const object s1 : " << s1.getValue1();
    // cout << "\nThe non-const function called by const object s : " << s.getValue1(); //Gives compiler error because
    return 0;
}